package com.gem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gem.entity.Order;
import com.gem.entity.OrderItem;
import com.gem.entity.UserAddress;
import com.gem.mapper.OrderItemMapper;
import com.gem.mapper.OrderMapper;
import com.gem.mapper.UserAddressMapper;
import com.gem.service.OrderItemService;
import com.gem.vo.ItemVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 刘聪
 * Created  on 2021/4/23
 */
@Service
public class OrderItemServiceImpl extends ServiceImpl<OrderItemMapper,OrderItem> implements OrderItemService {

    @Autowired
    private OrderItemMapper itemMapper;
    @Autowired
    private UserAddressMapper addressMapper;
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public ItemVO itemList(String orderNo,Integer addressId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("order_no", orderNo);
        List<OrderItem> itemList = (List<OrderItem>) itemMapper.selectList(wrapper);
        Order order = orderMapper.selectOne(wrapper);
        UserAddress address = addressMapper.selectById(addressId);
        ItemVO itemVO = new ItemVO();
        BeanUtils.copyProperties(address,itemVO);
        BeanUtils.copyProperties(order,itemVO);
        itemVO.setItems(itemList);
        return itemVO;
    }
}
